package com.example.product.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;
import java.util.HashMap;

@RestController
@Slf4j
//@NacosPropertySource(dataId = "product-dev.yml", groupId = "DEV_GROUP",autoRefreshed = true)
@RefreshScope
public class ProducController {


//    @Autowired
//    private R
    //@NacosValue(value = "${name.test}", autoRefreshed = true)
    @Value("${name.test}")
    private  String prot;

    @GetMapping("/proudct/getPort")
    @SentinelResource(value = "getPort", blockHandler = "blockHandlerHello")
    public HashMap<String,String>  getServicePort(){
      log.info("进入 Produ" + prot);

       return  new HashMap<String,String>() {{
           put("Produ",prot);
       }};
    }
    public String blockHandlerHello(BlockException e) {
        return "限流了";
    }

}
